package display {
	
	import events.ScreenEvent;
	import flash.display.MovieClip;
	import flash.events.Event;
	import gs.TweenLite;
	import utils.GlobalConfig;
	
	/**
	 * ...
	 * @author Vjekoslav Ratkajec
	 */
	public class Intro extends MovieClip {
		
		//{ region Stage elements
		
		public var content:MovieClip;
		public var contentMask:MovieClip;
		
		//} endregion
		
		private var animationDuration:Number = 2;
		private var stageStartX:Number = 0;
		private var stageStartY:Number = 0;
		
		public function Intro() {
			this.addEventListener(Event.ADDED_TO_STAGE, addedToStage);
		}
		
		private function addedToStage(event:Event):void {
			init();
		}
		
		private function init():void {
			setupMask();
			startAnimation();
		}
		
		private function setupMask():void {
			contentMask.width = this.stage.stageWidth;
			contentMask.height = this.stage.stageHeight;
			stageStartX = - (this.stage.stageWidth - GlobalConfig.STAGE_WIDTH) / 2;
			stageStartY = - (this.stage.stageHeight - GlobalConfig.STAGE_HEIGHT) / 2;
			contentMask.x = stageStartX - contentMask.width;
			contentMask.y = stageStartY;
		}
		
		private function startAnimation():void {
			TweenLite.to(contentMask, animationDuration, { x:stageStartX, onComplete:startAnimation_Complete } );
		}
		
		private function startAnimation_Complete():void {
			this.dispatchEvent(new ScreenEvent(ScreenEvent.SWITCH_SCREEN));
		}
	}
	
}